package domain.entities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

public class TranslatorDAO extends HibernateDaoSupport {
    private static final Logger log = LoggerFactory.getLogger(TranslatorDAO.class);


    protected void initDao() {
    }

    public List findAll() {
        log.debug("finding all Regions instances");
        try {
            String queryString = "from Traductor";
            return getHibernateTemplate().find(queryString);
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }

    public void attachDirty(Traductor instance) {
        log.debug("attaching dirty Traductor instance");
        try {
            getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }

    public Traductor findById(int id) {
        log.debug("getting Traductor instance with id: " + id);
        try {
            Traductor instance = (Traductor) getHibernateTemplate().get(
                    "domain.entities.Traductor", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }

    public void delete(Traductor traductor) {
        log.debug("deleting Traductor instance");
        try {
            getHibernateTemplate().delete(traductor);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    public List findByName(String name) {
        try {

            String queryString = "select t from Traductor t where name like '%" + name.trim() +"%'" +" or surname like '%" + name.trim() +"%'" ;
            return getHibernateTemplate().find(queryString);
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }
}
